import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'


/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/register',
    component: () => import('@/views/register/index'),
    hidden: true
  },
  {
    path: '/updatePassword',
    component: () => import('@/views/updatePassword/index'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  {
    path: '/',
    component: Layout,
    redirect: '/studentInfo',
    name: '个人管理',
    meta: { title: '个人管理', icon: 'el-icon-s-custom' },
    children: [
      {
        path: 'studentInfo',
        name: '个人信息',
        component: () => import('@/views/manage/studentInfo/studentInfo.vue'),
        meta: { title: '个人信息', icon: 'el-icon-s-custom' }
      }
    ]
  },

  {
    path: '/stu',
    component: Layout,
    redirect: '/stu/student',
    name: '学生管理',
    meta: { title: '学生管理', icon: 'el-icon-s-promotion' },
    children: [
      {
        path: 'student',
        name: '学生管理',
        component: () => import('@/views/manage/student/student'),
        meta: { title: '学生管理', icon: 'el-icon-s-promotion' }
      }
    ]
  },

  {
    path: '/pwd',
    component: Layout,
    redirect: '/pwd/studentPassword',
    name: '修改密码',
    meta: { title: '修改密码', icon: 'el-icon-s-grid' },
    children: [
      {
        path: 'studentPassword',
        name: '修改密码',
        component: () => import('@/views/manage/studentPassword/studentPassword'),
        meta: { title: '修改密码', icon: 'el-icon-menu' }
      }
    ]
  },


  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: constantRoutes
})

const router = createRouter()

export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
